from keystoneauth1.identity import v3
from keystoneauth1 import session
from keystoneclient.v3 import client as keyclient

#auth_url为keystone的endpoint入口
def get_keystone_session():
    auth = v3.Password(auth_url="http://192.168.10.10:5000/v3",
                       username="admin", password="000000",
                       project_name="admin", user_domain_name="demo",
                       project_domain_name="demo")
    sess = session.Session(auth=auth)
    return sess

#定义好keystone的接口
def get_keystone_client():
    sess = get_keystone_session()
    keystone = keyclient.Client(session=sess)
    return keystone
keystone = get_keystone_client()

#查询keystone项目列表
list = keystone.projects.list()
for p in list:
    print(p)
